//
//  UIWebView+Alert.m
//  EducationAdminClient
//
//  Created by 孙添凤 on 17/4/12.
//  Copyright © 2017年 周佳兴. All rights reserved.
//

#import "UIWebView+Alert.h"

@implementation UIWebView (Alert)


static BOOL status = NO;

static BOOL isEnd = NO;

//
-(void)webView:(UIWebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(id)frame{
//    UIAlertView* dialogue = [[UIAlertView alloc]initWithTitle:nil message:message delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
//    [dialogue show];
}

//
//- (NSString *) webView:(UIWebView *)view runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)text initiatedByFrame:(id)frame {
//    
//    return @"";
//    
//}
//
//
//- (BOOL)webView:(UIWebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(id)frame {
//    
//    UIAlertView *confirmDiag = [[UIAlertView alloc] initWithTitle:nil
//                                
//                                                          message:message
//                                
//                                                         delegate:self
//                                
//                                                cancelButtonTitle:@"取消"
//                                
//                                                otherButtonTitles:@"确定", nil];
//    
//    
//    
//    [confirmDiag show];
//    
//    
//    
//    CGFloat version = [[[UIDevice currentDevice] systemVersion] floatValue];
//    
//    if (version >= 7.) {
//        
//        while (isEnd == NO) {
//            
//            [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01f]];
//            
//            
//        }
//        
//    }else
//        
//    {
//        
//        while (isEnd == NO && confirmDiag.superview != nil) {
//            
//            [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01f]];
//            
//        }
//        
//    }
//    
//    isEnd = NO;
//    
//    return status;
//    
//}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    status = buttonIndex;
    
    isEnd = YES;
    if(buttonIndex==1){
     [[NSNotificationCenter defaultCenter]postNotificationName:@"webAlert" object:@"1"];
    }
    
    
}

@end
